<?php
/**
 * Created by PhpStorm.
 * User: Wlh
 * Date: 2018/7/2
 * Time: 17:46
 */
namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Helper extends Frontend{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = '*';
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = '*';

    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 官网主页
     */
    public function index()
    {
        return $this->view->fetch();
    }

    /**
     * 查询
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function search(){
        $keywords = input('get.keywords');
        if($keywords){
            $res = Db::table('bi_helper_center')->where('keywords','like',"%$keywords%")->select();
            $this->assign('res',$res);
        }else{
            $res = array(
                'status' => false,
                'msg'    => '未输入关键字'
            );
            return json($res);
        }
    }

    /**
     * 使用帮助
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function usinghelp(){
        $type_name = Db::table('bi_helper_classificate')->where('pid',0)->select();
        $this->assign('type_name',$type_name);
        $type_children = Db::table('bi_helper_classificate')->where('pid','<>',0)->select();
        $this->assign('type_children',$type_children);
        return $this->view->fetch();
    }

    public function getMaincontent(){
        $helper_center_id = input('post.helper_center_id');;
        $helper_center = Db::table('bi_helper_center')->where('classificate_id',$helper_center_id)->select();
        return json($helper_center);
    }
}